import request from '@/utils/request.js'

const supplierApi = {
  List: '/supplier/list',
  Add: '/supplier/add',
  Update: '/supplier/update',
  Delete: '/supplier/delete',
  TypeList: '/supplier/typeList'
}

const Map = {
  'ascend': 'asc',
  'descend': 'desc'
}

export function listSupplier (parameter) {
  return request({
    url: supplierApi.List,
    method: 'get',
    params: {
      supplierName: parameter.supplierName || null,
      createTime: parameter.createTime || null,
      type: parameter.type || null,
      page: parameter.page || 1,
      pageSize: parameter.pageSize || 10,
      order: Map[parameter.order] || 'asc'
    }
  })
}

export function addSupplier (parameter) {
  return request({
    url: supplierApi.Add,
    method: 'post',
    data: parameter
  })
}

export function updateSupplier (parameter) {
  return request({
    url: supplierApi.Update,
    method: 'put',
    data: parameter
  })
}

export function deleteSupplier (parameter) {
  return request({
    url: supplierApi.Delete,
    method: 'delete',
    params: {
      id: parameter
    }
  })
}

export function typeListSupplier () {
  return request({
    url: supplierApi.TypeList,
    method: 'get'
  })
}
